#include "AIGCJson.hpp"

using namespace std;
using namespace aigc;
class Student
{
public:
    string Name;
    int Age;

    AIGC_JSON_HELPER(Name, Age)
    AIGC_JSON_HELPER_RENAME("name", "age")
};

class BaseLeason
{
public:
    int Type;
    string StartTime;
    string EndTime;

    AIGC_JSON_HELPER(Type, StartTime, EndTime)
};

class EnglishLeason : public BaseLeason
{
public:
    string TeacherName;
    int Count;

    AIGC_JSON_HELPER(TeacherName, Count, Type)
    AIGC_JSON_HELPER_BASE((BaseLeason *)this)
};
//--------------------------------------------
class BaseLeason1
{
public:
    int Type;
    string StartTime;
    string EndTime;

    AIGC_JSON_HELPER(Type, StartTime, EndTime)
};

class MathLeason
{
public:
    string TeacherName;
    int Count;
    BaseLeason1 Leason;

    AIGC_JSON_HELPER(TeacherName, Count, Leason)
};

class AllLeason
{
public:
    int Count;
    std::list<BaseLeason1> Leasons;
    AIGC_JSON_HELPER(Count, Leasons)
};

class AllLeasonV
{
public:
    int Count;
    bool Has;
    std::vector<BaseLeason1> Leasons;
    AIGC_JSON_HELPER(Count, Has, Leasons)
};

enum EN_TEST {EN_TEST0=0,EN_TEST1};
class AllLeasonMap
{
public:
    int Count;
    bool Has;
    EN_TEST En;
    std::map<string,BaseLeason1> LeasonsMap;
    AIGC_JSON_HELPER(Count, Has, En, LeasonsMap)
};

//--------------------------------------------
int main(int argc, char *argv[])
{
    bool check;
    {
		Student person;
		JsonHelper::JsonToObject(person, R"({"name":"XiaoMing", "age":15})");

		string newjson;
		check = JsonHelper::ObjectToJson(person, newjson);
		cout << "person:" << check << newjson << endl;
    }
    //-------------------------------------------
    // 类继承
    {
		string testjson = R"({"TeacherName": "小红","Count" : 15,"Type"     : 1,"StartTime": "8:00","EndTime"  : "10:00"})";
		EnglishLeason leason;
		check = JsonHelper::JsonToObject(leason, testjson);

		string newjson;
		check = JsonHelper::ObjectToJson(leason, newjson);
		cout << "类继承:" << check << newjson << endl;
    }
   
    //----------------------------------------------------

    // 类型嵌套
    {
		string testjson1 = R"({"TeacherName": "XiaoHong",
                                              "Count" : 15,
                                              "Leason": {
                                                    "Type"     : 0,
                                                    "StartTime": "8:00",
                                                    "EndTime"  : "10:00"}})";
		MathLeason person1;
		check = JsonHelper::JsonToObject(person1, testjson1);

		string newjson;
		check = JsonHelper::ObjectToJson(person1, newjson);
		cout << "类型嵌套:" << check << newjson << endl;
    }
    
    //----------------------------------------------------------------
    // 标准容器：List
    {
		AllLeason all;
		check = JsonHelper::JsonToObject(all, R"({"Count" : 15,
                                              "Leasons": [{
                                                    "Type"     : 0,
                                                    "StartTime": "8:00",
                                                    "EndTime"  : "10:00"},
                                                    {
                                                    "Type"     : 1,
                                                    "StartTime": "8:00",
                                                    "EndTime"  : "10:00"}
                                                    ]})");

		string newjson;
		check = JsonHelper::ObjectToJson(all, newjson);
		cout << "List:" << check << newjson << endl;
    }
    //----------------------------------------
    // 标准容器：Vector
    {
		AllLeasonV allV;
		check = JsonHelper::JsonToObject(allV, R"({"Count" : 15,
                                               "Has": true,
                                              "Leasons": [{
                                                    "Type"     : 0,
                                                    "StartTime": "8:00",
                                                    "EndTime"  : "10:00"},
                                                    {
                                                    "Type"     : 1,
                                                    "StartTime": "8:00",
                                                    "EndTime"  : "10:00"}
                                                    ]})");
		string newjson;
		check = JsonHelper::ObjectToJson(allV, newjson);
		cout << "Vector:" << check << newjson << endl;
    }
    

    //----------------------------------------------------------------------
    // 标准容器：MAP
    {
		AllLeasonMap allM;
		check = JsonHelper::JsonToObject(allM, R"({"Count" : 15,
                                               "Has": true,
                                               "En": 1,
                                               "LeasonsMap": {
                                                    "Leason1": {
                                                        "Type"     : 0,
                                                        "StartTime": "8:00",
                                                        "EndTime"  : "10:00"},
                                                    "Leason2": {
                                                        "Type"     : 1,
                                                        "StartTime": "8:00",
                                                        "EndTime"  : "10:00"}
                                                    }})");
		string newjson;
		check = JsonHelper::ObjectToJson(allM, newjson);
		cout << "map:" << check << newjson << endl;
    }
    

    return 0;
}
